package com.lmaos.basetools.base;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.lang.model.type.NullType;
/**
 * 
 * @author lmaos
 *
 * <p>作者：张星宇</p>
 * <p>时间：2017年5月25日 下午10:10:31</p>
 * <p>说明:参数map	</p>
 *
 */
public class SParamMap extends ConcurrentHashMap<String, Object>{
	private static final long serialVersionUID = 1L;
	public SParamMap() {
	}
	public SParamMap(Map<String, Object> map) {
		super(map);
	}
	public SParamMap(int capacity) {
		super(capacity);
	}
	private String name;
	public SParamMap setName(String name) {
		this.name = name;
		return this;
	}
	public String getName() {
		return name;
	}
	
	@Override
	public Object put(String key, Object value) {
		if(value==null){
			return null;
		}
		return super.put(key, value);
	}
	public Object put(Class key, Object value) {
		return super.put(key.toString(), value);
	}
	
	@Override
	public Object get(Object key) {
		Object value = super.get(String.valueOf(key));
		if(value!=null&&value == NullType.class){
			value = null;
		}
		return value;
	}
	public <OBJ>OBJ getOBJ(String key){
		
		Object obj = super.get(key);
		if(obj == null||obj==NullType.class){
			return null;
		}
		return (OBJ)obj;
	}
	public byte getByte(String key){
		Object value = super.get(key);
		return SNumberUtils.toByte(value);
	}
	public short getShort(String key){
		Object value = super.get(key);
		return SNumberUtils.toShort(value);
	}
	public int getInt(String key){
		Object value = super.get(key);
		return SNumberUtils.toInt(value);
	}
	public long getLong(String key){
		Object value = super.get(key);
		return SNumberUtils.toLong(value);
	}
	public float getFloat(String key){
		Object value = super.get(key);
		return SNumberUtils.toFloat(value);
	}
	public double getDouble(String key){
		Object value = super.get(key);
		return SNumberUtils.toDouble(value);
	}
	public boolean getBoolean(String key){
		Object value = super.get(key);
		return SNumberUtils.toBoolean(value);
	}
	public String getString(String key){
		Object value = get(key);
		if(value == null){
			return null;
		}
		return String.valueOf(value);
	}
	public BigDecimal getBigDecimal(String key){
		Object value = get(key);
		return SNumberUtils.toBigDecimal(value);
	}
	public Date getDate(String key){
		Object value = get(key);
		if(value == null){
			return null;
		}
		if(value instanceof Date){
			return (Date) value;
		}
		long time = SNumberUtils.toLong(value,-1);
		if(time!=-1){
			return new Date(time);
		}
		return null;
	}
	public <T>List<T> getList(String key){
		Object obj = get(key);
		if(obj == null){
			return null;
		}
		return (List<T>)obj;
	}
}
